package com.xjscrm.console.common.util;

import com.xjscrm.console.entity.Route;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RouteDataProcessorUtil {


    public static Map<String, String> analysis(List<Route> routesData) {
        Map<String, String> pathAuthMap = new HashMap<>();
        for (Route route : routesData) {
            processRoute(route, pathAuthMap);
        }

//        pathAuthMap.forEach((path, auth) -> System.out.println("Path: " + path + ", Auth: " + auth));
        return pathAuthMap;
    }

    private static void processRoute(Route route, Map<String, String> pathAuthMap) {
        if (route != null && route.getApiAuth() != null) {
            for (Route apiAuth : route.getApiAuth()) {
                pathAuthMap.put(apiAuth.getPath(), apiAuth.getAuth());
            }
        }
        if (route.getRoutes() != null) {
            for (Route subRoute : route.getRoutes()) {
                processRoute(subRoute, pathAuthMap);
            }
        }
    }

}